#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minCost(vector<vector<int>>& costs) {
        int n = costs.size();

        vector<vector<int>> dp(n + 1, vector(3, 0));

        for (int i = 1; i < n + 1; i++)
        {
            dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + costs[i - 1][0];
            dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + costs[i - 1][1];
            dp[i][2] = min(dp[i - 1][1], dp[i - 1][0]) + costs[i - 1][2];

        }


        int ret = dp[n][1] < dp[n][2] ? dp[n][1] : dp[n][2];
        ret = dp[n][0] < ret ? dp[n][0] : ret;
        return ret;

    }
};